package com.ztgf.sys.api.client;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.sys.models.bo.SysConfigBO;
import com.ztgf.sys.models.dto.SysConfigDTO;
import com.ztgf.sys.models.service.ISysConfigService;
import com.ztgf.sys.models.vo.SysConfigVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 数据字典表控制器
 *
 * @author mxli
 * @Date 2020-05-27 10:03:34
 */

@RestController
@RequestMapping("/api/sysConfig")
@Slf4j
@Api(value = "SysConfigApiController",tags = "数据字典表Api接口")
public class SysConfigApiController {

    @DubboReference
    private ISysConfigService sysConfigService;

    @PostMapping("/getById")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<SysConfigDTO> getById(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }
        return new Result<>(sysConfigService.getById(id));
    }

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<SysConfigVO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        SysConfigVO vo = sysConfigService.selectById(id);

        return new Result<>(vo);
    }

    @ApiOperation(value = "获取取消订单信息",notes = "获取取消订单信息")
    @PostMapping("/getCancelOrderList")
    public Result<List<SysConfigDTO>> getCancelOrderList(){
        return new Result<>(sysConfigService.getCancelOrderList());
    }

    @ApiOperation(value = "数据字典表列表",notes = "数据字典表列表")
    @PostMapping("/queryPageList")
    public Result<Page<SysConfigDTO>> queryPageList(SysConfigBO bo){
       Wrapper<SysConfigDTO> wrapper = new EntityWrapper<>();
        if (bo.getStatus() != null){
            wrapper.eq("status", bo.getStatus());
        }
        Page<SysConfigDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = sysConfigService.selectPage(page, wrapper);

        return new Result<>(page);
    }
}
